package com.lichuang.dedao.city.service.impl;

import com.lichuang.dedao.city.entity.Comment;
import com.lichuang.dedao.city.entity.Note;
import com.lichuang.dedao.city.entity.Reply;
import com.lichuang.dedao.city.entity.User;
import com.lichuang.dedao.city.fingnclient.UserFeignClient;
import com.lichuang.dedao.city.mapper.CommentMapper;
import com.lichuang.dedao.city.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wp
 * @since 2019-07-13
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Autowired
    CommentMapper commentMapper;

    @Autowired
    UserFeignClient userFeignClient;

    @Override
    public List<Comment> selByNoteId(Integer notrId) {
        return null;
    }


    @Override
    public List<Comment> selByparentId(Integer notr_id) {
        return null;
    }

    /**
     * 笔记评论查询
     * @return
     */
    public List contextLoads(){
        List<Comment> firstList = commentMapper.selByNoteId(1);
        List<Comment> f = commentMapper.selByNoteId(1);
        Comment comment = new Comment();


        for (Comment o : firstList) {
            User list =  userFeignClient.selectUserById(o.getCommentUserId());
            o.setUsername(list.getNickName());
            o.setImg(list.getProfilePhoto());
        }




        List<Comment> thenList = commentMapper.selByparentId(1);

        for (Comment o : thenList) {
            User list =  userFeignClient.selectUserById(o.getCommentUserId());
            o.setUsername(list.getNickName());
            o.setImg(list.getProfilePhoto());
        }

        ArrayList<Reply> replies = new ArrayList<>();

        for(Comment o: firstList) {
            replies.add(new Reply((Comment) o));
        }
        List list =Reply.addAllNode(replies,thenList);

        System.out.println();

        Reply.show(list);

        return list;
    }



    public int insNoteComment(Comment comment){
        return commentMapper.insNoteComment(comment);
    }

}
